package gui;



import init.AppLauncher;

import java.awt.Component;
import java.util.Observable;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import prefuse.JRangeSlider;


public class Slider extends JInternalFrame implements IView {
	
	private JLabel label;
	
	public Slider(String title) {
		super(title);
		display();		
	}
	
	//for testing purposes
	public static void main(String[] args) {
	    //Schedule a job for the event-dispatching thread:
	    //creating and showing this application's GUI.
	    javax.swing.SwingUtilities.invokeLater(new Runnable() {
		    public void run() {
			new Slider("test");
		    }
		});
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void display() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(800, 80);
		getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
				
        final JRangeSlider slider = new JRangeSlider(1900, 2010, 1960, 2000, JRangeSlider.HORIZONTAL);
        
        slider.setThumbColor(null);
        
        label = new JLabel("Range = [ Active year from : " + slider.getLowValue() + ", Ceased year to : " + slider.getHighValue()  + "]");
        
        slider.addChangeListener(new ChangeListener() {
			
			public void stateChanged(ChangeEvent e) {
				
				label.setText("Range = [ Active year from : " + slider.getLowValue() + ", Ceased year to : " + slider.getHighValue()  + "]");
				AppLauncher.refreshApplet(slider.getLowValue(),slider.getHighValue());
			}
		});
        
		label.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		getContentPane().add(slider);
		getContentPane().add(label);
		//fen.pack();
		setVisible(true);
	}
}
